home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 21 code / Custom GX Printer Drivers / CustomWriter GX 1.0.1 / GlobalData.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.0 KB  |  96 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         GlobalData.c
  4.  
  5.     DESCRIPTION
  6.         Contains code that shows an alternate way to manage unique global
  7.         data for different message handler instances.  This method does
  8.         not require that you access the global data via a message override,
  9.         so it works great for callback situations.  (Remember, global data
  10.         set up by NewMessageGlobals and so forth can only be accessed when
  11.         you've gained control through a message override.  These global
  12.         data routines work whenever and however you've gained control.)
  13.  
  14.         We don't need to do things this way for this driver, (the normal
  15.         QuickDraw GX global data routines will work fine), but I figured we
  16.         needed an example of this method, so here it is.  Note that the
  17.         SetDriverGlobals and GetDriverGlobals routines are in NewApp.a.
  18.  
  19.     COPYRIGHT
  20.         Copyright © 1995 Apple Computer, Inc.
  21.         All rights reserved.
  22.     
  23.     Modification history
  24.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  25.                                     CustomBufferingAndIO.c.
  26.  
  27.         01/14/95 - Dave Hersey -    Begat.
  28.  
  29.     NOTE: Relevant goodies are listed in MPW's "Mark" menu.
  30.  
  31. */
  32.  
  33. #include "CommonDefines.h"
  34.  
  35.  
  36. /*    -----------------------------------------------------------------------
  37.  
  38.     CreateAndStoreGlobals is a routine we call to initialize and store a
  39.     handle in the are we allocated at the end of our NewApp.a jump table.
  40.     
  41.     This routine and its counterpart (DisposeGlobals) provide an alternate
  42.     method of handling global data in a driver.  The two calls provide a
  43.     method similar to GetMessageHandlerInstanceContext and
  44.     SetMessageHandlerInstanceContext, except that this method can be used
  45.     even if your code didn't receive control via a message override.  For
  46.     example, if your code is being executed from a dialog manager
  47.     callback.  The standard global data handling routines that are provided
  48.     with QuickDraw GX will only work if your code received control via a
  49.     message override.
  50.  
  51.     -----------------------------------------------------------------------    */
  52.  
  53. OSErr CreateAndStoreGlobals(DriverGlobalsHdl *drvrGlobalsHdl)
  54. {
  55.     OSErr    anErr;
  56.  
  57.     // Create a handle for our data, and store it in our jump table's
  58.     // data area.  Note that the routine SetDriverGlobals is in NewApp.a.
  59.  
  60.     *drvrGlobalsHdl = (DriverGlobalsHdl) TempNewHandle(sizeof(DriverGlobals), &anErr);
  61.     
  62.     if (!anErr)
  63.     {
  64.         (**drvrGlobalsHdl)->curFileRefNum = 0;
  65.         SetDriverGlobals(*drvrGlobalsHdl);
  66.     }
  67.  
  68.     return anErr;
  69. }
  70.  
  71.  
  72. /*    -----------------------------------------------------------------------
  73.  
  74.     DisposeGlobals is a routine that disposes of the global data we stored
  75.     in our jump table's data area via CreateAndStoreGlobals.
  76.  
  77.     -----------------------------------------------------------------------    */
  78.  
  79. void DisposeGlobals()
  80. {
  81.     DriverGlobalsHdl    drvrGlobalsHdl;
  82.  
  83.     // If a handle was stored in our jump table's global data area,
  84.     // dispose of it and store nil in its place.  This indicates
  85.     // that no valid globals are allocated.  Note that the routine
  86.     // GetDriverGlobals is in NewApp.a.
  87.  
  88.     drvrGlobalsHdl = GetDriverGlobals();
  89.  
  90.     if (drvrGlobalsHdl != nil)
  91.     {
  92.         DisposeHandle((Handle) drvrGlobalsHdl);
  93.         SetDriverGlobals(nil);
  94.     }
  95. }
  96.